<!DOCTYPE html>
<html lang="zh">

<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>页面</title>
    <!-- 引入Vue -->
    <script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/loading.js"></script>
    <link href="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/lib/theme-chalk/index.css" rel="stylesheet">


</head>

<body>
<div id="app">
    <el-container>
        <el-header>
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item>首页</el-breadcrumb-item>
                <el-breadcrumb-item>客户管理</el-breadcrumb-item>
            </el-breadcrumb>
        </el-header>
        <el-header>
            <el-row >
                <a href="/custom/add.page"><el-col :xs="8" :sm="8" :md="4" :lg="2" :xl="2">
                    <el-button type="primary" icon="el-icon-edit" >新增</el-button>
                </el-col></a>
                <el-col :xs="14" :sm="14" :md="8" :lg="8" :xl="8">
                    <el-input placeholder="请输入内容" @keyup.enter.native="enterSearch" v-model="keySearch">
                        <el-button slot="append" icon="el-icon-search" @click=search></el-button>
                    </el-input>
                </el-col>
            </el-row>
        </el-header>
        <el-main>
            <el-table :data="data.tableData" stripe border style="width:100%" highlight-current-row size="mini" tooltip-effect="dark" height="calc(100vh - 240px)">
                <el-table-column label="序号" align="center" width="50">
                    <template scope="scope"><span>{{scope.$index+(data.currentPage - 1) * data.pageSize + 1}}</span></template>
                    　　</el-table-column>
                　　<el-table-column prop="user_email" label="账号" align="center" :show-overflow-tooltip=true>
                　　</el-table-column>
                　　<el-table-column prop="user_name" label="用户名" align="center" :show-overflow-tooltip=true>
                　　</el-table-column>
                <el-table-column prop="user_phone" label="手机号" align="center" :show-overflow-tooltip=true>
                    　　</el-table-column>
                <el-table-column prop="user_dept" label="部门" align="center" :show-overflow-tooltip=true>
                    　　</el-table-column>
                　　<el-table-column prop="user_state" label="用户状态" align="center" :formatter="formatStatus" :show-overflow-tooltip=true>
                　　</el-table-column>
                　　<el-table-column label="操作" align="center" min-width="100">
                　　　　<template slot-scope="scope">
                　　　　　<template v-for="item in button">
                <el-button type="text"  @click="item.fn(scope.row.id)">{{item.name}}</el-button>
            </template>
                　　　　</template>
                　　</el-table-column>
            </el-table>
        </el-main>
        <el-footer>
            <el-row >
                <el-col >
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                   :page-sizes="[100, 500, 1000]" :page-size="data.pageSize" layout="total, sizes, prev, pager, next, jumper"
                                   :total="data.totalRecords" >
                    </el-pagination>
                </el-col>
            </el-row>
        </el-footer>
    </el-container>
</div>

<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/dist/vue.js"></script>
<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/vue-element/lib/index.js"></script>
<script src="https://pinzafile.oss-cn-shanghai.aliyuncs.com/publiccss/assets/global/plugins/jquery.min.js" type="text/javascript"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                data: {
                    tableData: [],
                    currentPage: 1, //当前页
                    pageSize: 100, //每页总数
                    totalRecords: 0, //总条数
                },
                keySearch: '',
                //后台权限列表拼接
                button: [],
            };
            show:false

        },

        methods: {
            //回车监听事件获取输入内容
            enterSearch(event) {
                this.data.currentPage=1;
                this.data.pageSize=100;
                this.keySearch = event.target.value;
                this.ajaxFunction();
            },
            //点击事件获取输入内容
            search() {
                this.data.currentPage=1;
                this.data.pageSize=100;
                this.ajaxFunction();
            },
            ajaxFunction(){
                var key =this.keySearch;
                var page = this.data.currentPage;
                var size= this.data.pageSize;
                var resultData = '';
                $.ajax({
                    url: '/custom/list.json',
                    type: 'post',
                    data: {key:key,page:page,size:size},
                    async: false,
                    dataType: 'json',
                    success: function (result) {
                        console.log(result.data)
                        if(result.ret){
                            resultData = result.data;
                        }
                    }
                });
                this.data.tableData = resultData.list;
                this.data.currentPage = resultData.pageIndex;
                this.data.pageSize = parseInt(resultData.size);
                this.data.totalRecords = resultData.total;
                this.button = resultData.operaButton;
                var tempVue=this;
                this.button.forEach(function (ele) {
                    ele.fn=tempVue[ele.fn]
                })
                console.log(resultData.operaButton);
            },
            //删除用户
            del(val) {
                this.$confirm('冻结或解冻用户, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    center: true
                }).then(() => {
                    var bool = false;
                    var err = "";
                    $.ajax({
                        url: '/user/cancel.json',
                        type: 'post',
                        data: {userId:val},
                        async: false,
                        dataType: 'json',
                        success: function (result) {
                            if(result.ret){
                                bool = result.ret;
                            }else{
                                err = result.msg;
                            }
                        }
                    });
                    if (bool){
                        this.$message({
                            type: 'success',
                            message: '操作成功'
                        });
                        this.ajaxFunction()
                    }else{
                        this.$message({
                            type: 'success',
                            message: err
                        });
                    }

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消操作'
                    });

                });
            },
            //修改用户
            modify(val) {
                console.log(val)
                window.location.href="/user/update.page?uid="+val;
            },
            //查看详情
            // detail(val) {
            //     console.log(val)
            // },
            async handleSizeChange(val) {
                <#--console.log(`每页: ${val}`);-->
                this.data.pageSize = val;
                this.ajaxFunction();

                //     var response = await axios.post("sda/fds?page="+val);
                //    this.data= response.data
            },
            //
            async handleCurrentChange(val) {

                <#--console.log(`当前页: ${val}`);-->
                <#--console.log(`每页：${this.data.pageSize}`);-->
                this.data.currentPage = val;
                this.ajaxFunction();
                //     var response = await axios.post("sda/fds?page="+val);
                //    this.data= response.data
            },
            //状态转换
            formatStatus: function (row, column) {
                return row.user_state == 99 ? '已冻结' : row.user_state ==11 ? '有效' :'未知';
            },

        },

        async mounted(){
            this.ajaxFunction();
        }
    })
</script>
</body>

</html>